//
//  WKPopDateView.swift
//  NewDelivery
//
//  Created by 天下宅 on 2016/12/16.
//  Copyright © 2016年 天下宅. All rights reserved.
//

import UIKit

protocol WKPopDateViewResult {
    func getResult(_ result:String)
}

class WKPopDateView: WKPopPickerBaseView {

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    var datePickerView:UIDatePicker!
    var thisDelegate:WKPopDateViewResult?
    override init()
    {
        super.init()
        datePickerView = UIDatePicker()
        self.contentView.addSubview(datePickerView)
        datePickerView.snp.makeConstraints { (make) in
            make.left.equalTo(self.contentView).offset(10)
            make.right.equalTo(self.contentView).offset(-10)
            make.top.equalTo(self.cancleBtn.snp.bottom).offset(5)
            make.height.equalTo(120)
        }
        datePickerView.locale =  Locale.init(identifier:  "zh_CN")
        datePickerView.timeZone = NSTimeZone.local
        datePickerView.maximumDate = Date.init(timeIntervalSinceNow: 0)
        datePickerView.datePickerMode = .date
        thisHeight += 120 + 10
        self.finishLayout()
    }
    
    override func btnClick(sender: UIButton) {
        if sender.tag == 101 {
            //确定
//            let index = pickerView.selectedRowInComponent(0)
//            let result = datasource[index]
//            popPickerViewDelegate?.popPickerViewClick(result, pickerView: self)
            let str = String.timeStampToString(timeS: datePickerView.date.timeIntervalSince1970 * 1000, dateStyle: "yyyy-MM-dd")
            thisDelegate?.getResult(str)
//            print(datePickerView.date.timeIntervalSince1970)
        }
        
        self.show(flag: false)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
